package com.traffic.fuwu.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.traffic.fuwu.dao.WhiteListMapper;
import com.traffic.fuwu.mybatis.pojo.WhiteList;
import com.traffic.fuwu.mybatis.pojo.WhiteListExample;
import com.traffic.fuwu.service.WhiteListService;

@Service
public class WhiteListServiceImpl implements WhiteListService {
	@Autowired
	private WhiteListMapper whiteListMapper;

	@Override
	public List<WhiteList> getFindWhiteList(Map<String, Object> conditions) {
		try {
			List<WhiteList> list = whiteListMapper.getFindWhiteList(conditions);
			if (list != null && list.size() != 0) {
				return list;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public int getFindWhiteListCount(Map<String, Object> conditions) {
		try {
			int count = whiteListMapper.getFindWhiteListCount(conditions);
			if (count != 0) {
				return count;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public WhiteList getById(int wlId) {
		WhiteListExample example = new WhiteListExample();
		example.or().andWlIdEqualTo(wlId);

		try {
			List<WhiteList> list = whiteListMapper.selectByExample(example);
			if (list != null && list.size() != 0) {
				WhiteList whiteList = list.get(0);
				return whiteList;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}

	@Override
	public void addWhiteList(WhiteList whiteList) {
		whiteListMapper.insert(whiteList);
	}

	@Override
	public void updateWhiteList(WhiteList whiteList) {
		whiteListMapper.updateByPrimaryKey(whiteList);
		
	}

}
